//
//  ViewController.swift
//  SwiftDemo
//
//  Created by 李国卿 on 2020/1/7.
//  Copyright © 2020 guoqing.li. All rights reserved.
//

import UIKit



class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let digitName = [0:"Zero",1:"One",2:"Two",3:"Three",4:"Four",5:"Five",6:"Six",7:"Seven",8:"Eight",9:"Nine"]
        let numbers = [16,31,510]
        let strings = numbers.map { (number) -> String in
            var number = number
            var output = ""
            repeat{
                output = digitName[number % 10]!+output
                number /= 10
            }while number > 0
            return output
        }
        print("strings------\(strings)")
//        func greet(_ person: String, on day: String) -> String {
//            return "Hello \(person), today is \(day)."
//        }
//       let result = greet("John", on: "Wednesday")
//
//        print("result----\(result)")
//        let vegetable = "red pepper"
//        switch vegetable {
//        case "celery":
//            print("Add some raisins and make ants on a log.")
//        case "cucumber", "watercress":
//            print("That would make a good tea sandwich.")
//        case let x where x.hasSuffix("pepper"):
//            print("Is it a spicy \(x)?")
//        default:
//            print("Everything tastes good in soup.")
//        }
//        let optionalName:String? = "li lei"
//        var greeting:String = "hello"
//        if optionalName != nil {
//            greeting = "hello +\(String(describing: optionalName))"
//        }else{
//            greeting = "hello war"
//        }
//        if let name = optionalName{
//            greeting = "Hello, \(name)"
//        }else{
//            greeting = "Hello nil"
//        }
//        print("greeting:\(greeting)")
//        let num:Float = 4
//        print("num:\(num)")
//        //捕获值
//        let label = "this width is "
//        let width = 94
//        let labelWidth = label + String(width)
//        print("labelWidth-------\(labelWidth)")
//        let calu = Calulator(a: 600, b: 300);
//        calu.total(c: 20);
        
///
//        let divide = {(num1:Int,num2:Int) -> Int in
//            return num1/num2
//        }
        
//        print("divide------\(divide(40,20))")
        
        //闭包表达式
//        let names = ["AE","AT","S","E","DE"]
        //使用普通函数(或内嵌函数)提供排序功能,闭包函数类型需为(String, String) -> Bool
//        func backFoward(str1:String,str2:String)->Bool{
//            return str1<str2
//        }
//        let reversed = names.sorted(by: backFoward)
        
//        print("reversed---\(reversed)")
        
        //Swift 自动为内联函数提供了参数名称缩写功能，您可以直接通过$0,$1,$2来顺序调用闭包的参数
        
//        let reversed = names.sorted(by: >)
        //
//        let reversed1 = names.sorted(){$0 > $1}
//
//        print("reversed---\(reversed)")
//        print("reversed1---\(reversed1)")
        
        
        
        
//        print("result---\(self.pow(num1: 5, num2: 3))");
//        print(self.runoob(name:"菜鸟网络：", site:"www.cainiao.com"))
//        let someDict:[Int:String] = [1:"one",2:"two",3:"three"]
//        for (key,vlaue) in someDict{
//            print("key---\(key),vlaue--\(vlaue)")
//        }
//        let firstValue = someDict[1]!
//        let twoValue = someDict[2]!
//        let threeValue = someDict[3]!
//        someDict[1] = "four"
//        let newValue = someDict[1]!
//        print("firstValue---\(firstValue)")
//        print("newValue---\(newValue)")
//        print("twoValue---\(twoValue)")
//        print("threeValue---\(threeValue)")
    }
    func test1(){
        
        let intsA = [Int](repeating: 2, count: 2)
        let intsB = [Int](repeating: 1, count: 3)
        let intsC = intsA + intsB
        for item in intsC {
            print("item---\(item)")
        }
        
        var someStrs = [String]()
        someStrs.append("Aplle")
        someStrs.append("Amazon")
        someStrs.append("Runoob")
        someStrs += ["Goole"]
        for (index,item) in someStrs.enumerated() {
            print("index---\(index)所在的位置\(item)")
        }
    }
    func runoob(name:String,site:String) -> String {
        return name+site;
    }
    func pow(num1:Int,num2:Int) -> Int {
        var result = num1;
        for _ in 1..<num2 {
            result = result*num1
        }
        return result
    }

}

